import { CopyControllerBase } from "./CopyControllerBase";
import { CopyMountBoxView } from "../copyMount/CopyMountBoxView";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../../../Message/Command/EPublicCommand";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { DataEvent } from "../../../events/DataEvent";
import { CopyMountFrontInfo } from "../copyMount/CopyMountFrontInfo";
import { CopyMountBackInfo } from "../copyMount/CopyMountBackInfo";
import { TodayNotTipUtil } from "../../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../../component/gconst/TodayNoTipsConst";
import { Language } from "../../../../../extend/language/Language";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { GameProxy } from "../../../mvc/GameProxy";
import { SCopyMountCopyInfo } from "../../../../../Message/Public/SCopyMountCopyInfo";
import { MessageBlock } from "../../../../../Framework/MQ/MessageBlock";
type int = number;
//class CopyMountController
    
    export  class CopyMountController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        public get mainView(): CopyMountBoxView
        {
            if (this._mainView == null) 
            {
                this._mainView = new CopyMountBoxView();
            }
            return this._mainView;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicCopyMountKillBoss, this.onECmdPublicCopyMountKillBoss);
            return;
        }

        protected /* override */ addListener(): void
        {
            Dispatcher.addEventListener(EventName.CopyMountShowMainView, this.onCopyMountShowMainView);
            Dispatcher.addEventListener(EventName.CopyMountClickClose, this.onCopyMountClickClose);
            Dispatcher.addEventListener(EventName.CopyMountClickCard, this.onCopyMountClickCard);
            Dispatcher.addEventListener(EventName.CopyMountClickCardSucess, this.onCopyMountClickCardSucess);
            return;
        }

        protected /* override */ removeListener(): void
        {
            Dispatcher.removeEventListener(EventName.CopyMountShowMainView, this.onCopyMountShowMainView);
            Dispatcher.removeEventListener(EventName.CopyMountClickClose, this.onCopyMountClickClose);
            Dispatcher.removeEventListener(EventName.CopyMountClickCard, this.onCopyMountClickCard);
            Dispatcher.removeEventListener(EventName.CopyMountClickCardSucess, this.onCopyMountClickCardSucess);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            LoaderHelp.addResCallBack(ResFileConst.copyMount, this.onLoadBmResource);
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            return;
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            this.mainView.hide();
            cache.copy.copyMountKillBossInfoArr = [];
            cache.copy.copyMountCostTime = 1;
            return;
        }

        public /* override */ stageResize(): void
        {
            this.mainView.stageResize();
            return;
        }

        /* internal  */onCopyMountClickCardSucess(arg1: DataEvent): void
        {
            var loc1=arg1.data as CopyMountFrontInfo;
            if (loc1.isHad == 0) 
            {
                cache.copy.copyMountCostTime = cache.copy.copyMountCostTime + 1;
                this.mainView.updateCost(cache.copy.copyMountCostTime);
            }
            this.mainView.setFrontData(loc1);
            return;
        }

        /* internal  */onCopyMountClickCard(arg1: DataEvent): void
        {
            var loc1=arg1.data["backInfo"] as CopyMountBackInfo;
            var loc2=arg1.data["cost"] as int;
            if (loc2 > 0) 
            {
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.CopyMountCostYBWarnning, this.getLuckyBagCostYBWarnning, Language.getStringByParam(72008, loc2), null, Alert.OK | Alert.CANCEL, null, null, null, 4, loc1);
            }
            else 
            {
                this.getLuckyBagCostYBWarnning([loc1]);
            }
            return;
        }

        /* internal  */getLuckyBagCostYBWarnning(arg1: Array<any>): void
        {
            var loc1=arg1[0] as CopyMountBackInfo;
            GameProxy.copy.getMountCopyDrop(loc1.bossId, loc1.modelId, loc1.isHad);
            return;
        }

        /* internal  */onCopyMountClickClose(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (this.mainView.isAllOpenCurBoss()) 
            {
                this.replaceReq([loc1]);
            }
            else 
            {
                TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.CopyMountCloseToday, this.replaceReq, Language.getString(74201), null, Alert.OK | Alert.CANCEL, null, null, null, 4, loc1);
            }
            return;
        }

        /* internal  */replaceReq(arg1: Array<any>): void
        {
            var loc2=null;
            cache.copy.copyMountCostTime = 1;
            var loc1=arg1[0] as int;
            var loc3=0;
            while (loc3 < cache.copy.copyMountKillBossInfoArr.length) 
            {
                loc2 = cache.copy.copyMountKillBossInfoArr[loc3];
                if (loc1 == loc2.reserveValue) 
                {
                    cache.copy.copyMountKillBossInfoArr.splice(loc3, 1);
                    break;
                }
                ++loc3;
            }
            if (cache.copy.copyMountKillBossInfoArr.length > 0) 
            {
                this.mainView.setBackData(this.infoProcess(cache.copy.copyMountKillBossInfoArr[0] as SCopyMountCopyInfo));
                this.mainView.show();
            }
            else 
            {
                this.mainView.hide();
            }
            return;
        }

        /* internal  */onECmdPublicCopyMountKillBoss(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SCopyMountCopyInfo;
            cache.copy.copyMountKillBossInfoArr.push(loc1);
            if (this.mainView.isHide) 
            {
                this.mainView.setBackData(this.infoProcess(loc1));
                this.mainView.show();
            }
            return;
        }

        /* internal  */infoProcess(arg1: SCopyMountCopyInfo): Array<any>
        {
            var loc2=null;
            var loc3=null;
            var loc1=[];
            var loc4=0;
            var loc5=arg1.cardInfo;
            for (loc3 in loc5) 
            {
                loc2 = new CopyMountBackInfo();
                loc2.bossId = arg1.reserveValue;
                loc2.modelId = loc3;
                loc2.isHad = arg1.cardInfo[loc3];
                loc1.push(loc2);
            }
            loc1.sortOn("isHad", Array.NUMERIC);
            return loc1;
        }

        /* internal  */onCopyMountShowMainView(arg1: DataEvent): void
        {
            var loc1=new SCopyMountCopyInfo();
            var loc2=new SCopyMountCopyInfo();
            var loc3;
            (loc3 = new Map<any, any> /* flash.utils.Dictionary */())["37035800"] = 1;
            loc3["37035900"] = 0;
            loc3["37036000"] = 1;
            loc3["37036100"] = 0;
            var loc4;
            (loc4 = new Map<any, any> /* flash.utils.Dictionary */())["sz000001"] = 1;
            loc4["sz000002"] = 0;
            loc4["sz000009"] = 1;
            loc4["sz000007"] = 0;
            loc1.reserveValue = 10;
            loc1.cardInfo = loc3;
            loc2.reserveValue = 20;
            loc2.cardInfo = loc4;
            cache.copy.copyMountKillBossInfoArr.push(loc1);
            cache.copy.copyMountKillBossInfoArr.push(loc2);
            if (this.mainView.isHide) 
            {
                this.mainView.setBackData(this.infoProcess(loc1));
            }
            this.mainView.show();
            return;
        }

        /* internal */ /* var */_mainView: CopyMountBoxView;
    }
